public class Main {
    public static void main(String[] args) {

    }
}
class Solution {
    public int longestOnes(int[] nums, int k) {
        int ret = 0;
        for (int left = 0,right = 0,count = 0;right < nums.length;right++) {
            //进窗口
            if (nums[right]==0) {
                count++;
            }
            //出窗口
            while (count>k) {
                if (nums[left++]==0) {
                    count--;
                }
            }
            ret = Math.max(ret,right-left+1);
        }
        return ret;
    }
}